<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="Generator" content="xnr®">
  <meta name="Author" content="小男人-923227829@qq.com">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>后台管理系统</title>
  <link rel="stylesheet" href="inc/layui/css/layui.css">
  <link rel="stylesheet" href="css/comm.css">
  <style type="text/css">
    .layui-nav-item.layui-this a,
    .layui-nav-item.layui-this a:hover,
    .layui-nav-item.layui-this a:after {
      background-color: #2F343D;
    }

    .layui-tab-content {
      background-color: #F5F5F5;
    }
  </style>
</head>

<body class="layui-layout-body" style="padding: 0;">
  <!-- 布局容器 -->
  <div class="layui-layout layui-layout-admin">
    <!-- 头部 -->
    <div class="layui-header">
      <div class="layui-main">
        <!-- logo -->
        <a href="/" style="color: #c2c2c2; font-size: 18px; line-height: 60px;" id="cname"></a>
        <!-- 水平导航 -->
        <ul class="layui-nav" style="position: absolute; top: 0; right: 0; background: none;">
          <li class="layui-nav-item">
            <a href="javascript:;">
              <img src="/img/icon/cus.png" style="margin-right:5px;" /><span id="name" value=""></span>
            </a>
            <dl class="layui-nav-child">
              <dd>
                <a href="javascript:;" id="uppwd">
                  修改密码
                </a>
              </dd>
              <dd>
                <a href="javascript:;" onclick="outlogin()">
                  退出登录
                </a>
              </dd>
            </dl>
          </li>
          <!--<li class="layui-nav-item">-->
          <!--<a href="javascript:;">-->
          <!--<i class="layui-icon layui-icon-notice"></i>-->
          <!--<span class="layui-badge-dot"></span>-->
          <!--</a>-->
          <!--</li>-->
        </ul>
      </div>
    </div>
    <!-- 侧边栏 -->
    <div class="layui-side layui-bg-black" style="background-color: 3F4652;">
      <div class="layui-side-scroll">
        <ul class="layui-nav layui-nav-tree" lay-filter="left-nav" style="border-radius: 0;padding-top: 0px"></ul>
      </div>
    </div>
    <!-- 主体 -->
    <div class="layui-body" id="tabrightmenu">
      <!-- 顶部切换卡 -->
      <div class="layui-tab layui-tab-brief" lay-filter="top-tab" lay-allowclose="true" style="margin: 0;">
        <ul id="top-tab" class="layui-tab-title"></ul>
        <div class="layui-tab-content">
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="layui-footer" style="text-align: center; line-height: 44px;" id="foots">
      sss
    </div>
  </div>

</body>
<script type="text/html" id="formTpl">
  <div id="form" class="layui-form" style="margin-top: 20px;margin-right:40px;">
    <div class="layui-form-item">
      <label class="layui-form-label">原密码</label>
      <div class="layui-input-block">
        <input value="" type="password" name="oldpassword" lay-verify="required" id="oldpassword" autocomplete="off"
          placeholder="请输入原密码" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">新密码</label>
      <div class="layui-input-block">
        <input value="" type="password" name="newPwdTwo" lay-verify="required" id="newPwdTwo" autocomplete="off"
          placeholder="请输入新密码" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">新密码</label>
      <div class="layui-input-block">
        <input value="" type="password" name="newPwdone" lay-verify="required" id="newPwdone" autocomplete="off"
          placeholder="请再次输入新密码" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-layer-btn ">
        <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="sub">保存</button>
        <button class="layui-btn layui-btn-primary" id="closeform">清空</button>
      </div>
    </div>
  </div>
</script>
<script type="text/html" id="upimgTpl">
  <div style="text-align:center; width:100px;height:140px;display:inline-block;">
    <img onclick="top.Comm.OSS.showimg(this)" style="margin:0 10px 10px 0;" width="auto" height="100" data="{{d.key}}"
      src="{{Comm.OSS.getImgUrl(d.key)}}" class="layui-upload-img">
    <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="$(this).parent().remove()">删除</button>
  </div>
</script>

<script type="text/javascript" src="inc/layui/layui.js"></script>
<script type="text/javascript" src="inc/g.js"></script>
<script type="text/javascript">
  var cms = null;
  var dates = new Date();
  dates.getFullYear()
  var s = 'Copyright &copy;' + dates.getFullYear() + ' Powered by ' + config.PowerBy;

  function pageload() {
    $('#cname').html(config.CName + "管理后台")
    $('#foots').html(s);
    layui.config({
      base: 'inc/'
    }).extend({
      tabrightmenu: '../inc/layui/lay/tabrightmenu'
    });
    /**
     * 初始化整个cms骨架
     */
    layui.use(['cms', 'laytpl', 'form', 'tabrightmenu'], function () {
      cms = layui.cms('left-nav', 'top-tab');
      Comm.tabrightmenu = layui.tabrightmenu;
      var user = Comm.db('user');
      Comm.menus = [];

      $('#name').html(user.customerName);
      AJAX.GET('/admin/menu/button/list?', function (d) {
        if (d.code == 1) {
          Comm.buttonList = d.data;
          getMenu();
        }
      })

      function getMenu() {
        AJAX.GET("/admin/menu/myList?force=1&roleId=" + user.roleId, function (dd) {
          if (dd.code == 1) {
            for (i in dd.data) {
              var e = dd.data[i];
              Comm.menus.push({
                id: e.menuId * 1,
                pid: e.pid * 1,
                node: e.menuName,
                url: e.url,
                icon: e.icon,
                btnId: e.btnId
              });
            }
            initmenu();
          } else {
            Comm.msg("拉取菜单失败")
          }
        });
      }

      function initmenu() {
        cms.addNav(Comm.menus, 0, 'id', 'pid', 'node', 'url');
        cms.bind(60 + 41 + 20 + 44); //头部高度 + 顶部切换卡标题高度 + 顶部切换卡内容padding + 底部高度
        cms.clickLI(0);

        Comm.tabrightmenu.render({
          container: '#tabrightmenu',
          filter: 'top-tab',
        });
      }

      $("#uppwd").click(function () {
        Comm.laytpl($("#formTpl").html()).render({}, function (html) {
          //多窗口模式，层叠置顶
          Comm.layer.open({
            type: 1,
            title: '修改密码',
            area: ['400px', '360px'],
            //shade: 0.3,
            //maxmin: true,
            content: html,
            ///zIndex: layer.zIndex, //重点1
            success: function (layero) {
              //验证必填项
              Comm.form.verify();
              //监听指定开关
              Comm.form.on('submit(sub)', function (data) {
                if (data.field.oldpassword == data.field.newPwdone) {
                    Comm.layer.msg("新旧密码一致!", {
                      icon: 1
                    });
                    Comm.layer.closeAll();
                  return
                }
                if (data.field.newPwdTwo != data.field.newPwdone) {
                  Comm.layer.msg("两次新密码输入不同!", {
                    icon: 5
                  });
                  return
                }
                data.field.customerId = user.customerId;
                AJAX.POST('/admin/customer/staff/modifyPw', data.field, function (d) {
                  if (d.code == 1) {
                    Comm.layer.msg("修改成功!请重新登录", {
                      icon: 1
                    });
                    Comm.layer.closeAll();
                    Comm.db("Authorization", null)
                    Comm.db("user", null)
                    //执行重载
                    Comm.go('login.html');
                  } else {
                    Comm.layer.msg(d.msg, {
                      icon: 5
                    })
                  }
                })
              });
              $("#closeform").click(function () {
                Comm.layer.closeAll();
              })
            },
          });
        })
      })
    });
  }

  function outlogin() {
    Comm.confirm("确定退出登录", function () {
      AJAX.POST('/admin/customer/logout', function (d) {})
      Comm.db("Authorization", null)
      Comm.db("user", null)
      Comm.go('login.html')
    })
  }
</script>

</html>